package com.itheima.project1.Controller;

import com.itheima.project1.Pojo.User;
import com.itheima.project1.Pojo.result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.itheima.project1.Service.userService;
@RestController
@Slf4j
@RequestMapping("/user")
public class userController {
    @Autowired
    private userService userservice;
    //根据id查询
    @GetMapping("/{id}")
    public result userList(@PathVariable Integer id){
        return result.success(userservice.userLIst(id));
    }
    //添加数据
    @PostMapping
    public result userInsert(@RequestBody User user){
        userservice.userInsert(user);
        return result.success();
    }
    //根据id删除数据
    @DeleteMapping("/{id}")
    public result userDelete(@PathVariable Integer id){
        userservice.userDelete(id);
        return result.success();
    }
    //根据id修改数据
    @PutMapping("/{id}")
    public result userUpdate(@PathVariable Integer id,@RequestBody User user){
        log.info("传递的路径参数和数据：{},{}",id,user);
        userservice.userUpdate(id,user);
        return result.success();
    }
}
